package com.bw.module_staff.view

import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_base.path.RouterPath
import com.bw.lib_common.view.BaseMvvmActivity
import com.bw.module_staff.R
import com.bw.module_staff.adapter.StaffAdapter
import com.bw.module_staff.databinding.ActivityStaffBinding
import com.bw.module_staff.entity.StaffEntity
import com.bw.module_staff.viewmodel.StaffViewModel
import dagger.hilt.android.AndroidEntryPoint
/**
 * 工单-智慧园区-人员管理
 */


@Route(path = RouterPath.PATH_STAFF_ACTIVITY)
class StaffActivity : BaseMvvmActivity<ActivityStaffBinding>() {
    private val vm by lazy { ViewModelProvider(this)[StaffViewModel::class.java] }
    var technology = 0
    var market = 0
    private var list:MutableList<StaffEntity> = mutableListOf()
    private lateinit var stateAdapter :StaffAdapter
    override fun initView() {

        mDataBinding.imageView.setOnClickListener { finish() }
        stateAdapter = StaffAdapter(list)
        mDataBinding.rvStaff.adapter = stateAdapter
        mDataBinding.rvStaff.layoutManager = LinearLayoutManager(this)
        mDataBinding.addStaff.setOnClickListener {
            ARouter.getInstance().build(RouterPath.PATH_ADD_STAFF_ACTIVITY).navigation()
        }

        vm.staffSuccess.observe(this){
            list.clear()
            list.addAll(it)
            stateAdapter.notifyDataSetChanged()
            technology = 0
            market = 0
            it.forEach {
                if (it.departmentId == 17){
                    technology++

                }else if (it.departmentId == 18){
                    market++

                }
            }
            mDataBinding.technology.text = technology.toString()+"人"
            mDataBinding.market.text = market.toString()+"人"
        }
    }

    override fun getLayoutId(): Int = R.layout.activity_staff

    override fun observeDataChange() {

    }

    override fun onResume() {
        super.onResume()
        vm.getStaff()
    }


}